﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace Unity.Game.ElisAdvance.ElisScript
{
    //玩家elis引入事件
    public class ElisState_Jump
    {

        public static void onFixedProc(ElisActiveObject activeObject, float horiztantlKey)
        {

            if (horiztantlKey != 0.0f)
            {
                activeObject.onActiveObjectMoveEvent(horiztantlKey);
            }
            else
            {
                activeObject.getVar("GLOBAL_horiztantlKey").clear_vector();
            }


            if (KeyPressEvent.isKeyPressDownDash())
            {
                if (activeObject.getVar("JumpDashFlag").get_vector(0) == 0)
                {
                    activeObject.getVar("JumpDashFlag").set_vector(0, 1);
                    activeObject.clearStateVector();
                    activeObject.pushStateVector(0);
                    activeObject.setState(State.STATE_DASH);
                }


            }

            if (KeyPressEvent.isKeyPressDownAttack())
            {
                if (activeObject.getVar("JumpAttackFlag").get_vector(0) == 0)
                {
                    activeObject.getVar("JumpAttackFlag").set_vector(0, 1);
                    activeObject.clearStateVector();
                    activeObject.pushStateVector(0);
                    activeObject.setState(State.STATE_JUMP_ATTACK);
                }

            }
            

            /*
            if (activeObject.isFrontFloor())
            {
                if (activeObject.getDirection() == Direction.LEFT)
                {
                    if (KeyPressEvent.isKeyPressLeft())
                    {

                    }
                }
                else if (activeObject.getDirection() == Direction.RIGHT)
                {
                    if (KeyPressEvent.isKeyPressRight())
                    {
                        activeObject.clearStateVector();
                        activeObject.pushStateVector(0);
                        activeObject.pushStateVector(1.0f);
                        activeObject.setState(State.STATE_HOLD_WALL);
                    }
                }
            }
            */

        }
        public static void onProc(ElisActiveObject activeObject)
        {

            if (activeObject.getStateVector(0) == 0)
            {

                if (!activeObject.isUpMove() || activeObject.isUp())
                {
                    activeObject.clearStateVector();
                    activeObject.pushStateVector(2);
                    activeObject.setState(State.STATE_JUMP);
                    return;
                }
            }

            if (activeObject.getStateTimer() > 0.2f)
            {
                if (Com.checkObjectTime(activeObject, "GLOBAL_JumpLandTimeEvent", 0.1f) && activeObject.isLand())
                {
                    activeObject.setCurrentPos(activeObject.getXPos(), activeObject.getYPos() - 0.05f);
                    activeObject.clearStateVector();
                    activeObject.setState(State.STATE_STAND);
                    return;
                }

            }



        }

        public static void onSetState(ElisActiveObject activeObject)
        {
            
            activeObject.getVar("GLOBAL_horiztantlKey").clear_vector();
            

            if (activeObject.getStateVector(0) == 0)
            {
                activeObject.getGravityEvent().setEnable(false);
                activeObject.getGravityEvent().refreshGravity();
                activeObject.getAniManager().setAni("Jump");
                activeObject.setXVelocity(0.0f);
                activeObject.setYVelocity(6.0f);
            }
            else if (activeObject.getStateVector(0) == 1)
            {
                activeObject.getAniManager().setAni("JumpLand");
                activeObject.getGravityEvent().setEnable(false);
                activeObject.getGravityEvent().refreshGravity();
                activeObject.setXVelocity(0.0f);

            }
            else if (activeObject.getStateVector(0) == 2)
            {
                activeObject.getAniManager().setAni("JumpLand");

            }
        }
    }
}